package proxies
{	
	import com.adobe.net.URI;
	import com.adobe.serialization.json.JSON;
	
	import core.PutIoLoader;
	import core.PutIoLoaderManager;
	import core.events.PutIoErrorEvent;
	import core.events.PutIoResultEvent;
	
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.IOErrorEvent;
	import flash.net.URLLoader;
	import flash.net.URLLoaderDataFormat;
	import flash.net.URLRequest;
	import flash.net.URLRequestHeader;
	import flash.net.URLRequestMethod;
	import flash.net.URLVariables;
	
	import mx.controls.Alert;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.http.HTTPService;
	
	import proxies.events.ProxyEvent;
	import proxies.events.ProxyEventsDispatcher;
	
	public class Proxy
	{				
		private var name:String = "";
		
		private var putIoLoaderManager:PutIoLoaderManager = PutIoLoaderManager.getInstance();
		private var proxyEventDispatcher:ProxyEventsDispatcher = ProxyEventsDispatcher.getInstance();	
		
		public function Proxy(_name:String)
		{
			this.name = _name;
		}
				
		public function sendRequest(methodName:String, result:Function, error:Function = null, parameters:Object = null):void
		{			
			var loaderId:String = putIoLoaderManager.initiatingConnection(this.name, methodName, result, error, parameters);			
			putIoLoaderManager.load(loaderId);
		}		
		
		public function dispatchEvent(event:ProxyEvent):void
		{
			proxyEventDispatcher.dispatchEvent(event);
		}
	}
}